package com.ylq.todolsitserver.service.impl;

import com.ylq.todolsitserver.entity.Task;
import com.ylq.todolsitserver.mapper.TaskMapper;
import com.ylq.todolsitserver.service.TaskService;
import com.ylq.todolsitserver.vo.TaskVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class TaskServiceImpl implements TaskService {

    private final TaskMapper taskMapper;

    @Autowired
    public TaskServiceImpl(TaskMapper taskMapper) {
        this.taskMapper = taskMapper;
    }

    @Override
    public Task createTask(TaskVO taskVO) {
        taskMapper.insert(taskVO);
        return taskMapper.findById(taskVO.getId());
    }

    @Override
    public List<Task> getAllTasks(String status, String priority, Integer categoryId, Boolean upcoming) {
        return taskMapper.findAll(status, priority, categoryId, upcoming);
    }

    @Override
    public Task getTaskById(Integer id) {
        return taskMapper.findById(id);
    }

    @Override
    public Task updateTask(Integer id, TaskVO taskVO) {
        taskVO.setId(id);
        taskMapper.update(taskVO);
        return taskMapper.findById(id);
    }

    @Override
    public void deleteTask(Integer id) {
        taskMapper.delete(id);
    }

    @Override
    public void updateTaskStatus(Integer id, String status) {
        taskMapper.updateStatus(id, status);
    }
}